'''
* This is the projet for Brtc LlmOps Platform
* @Author Leon-liao <liaosiliang@alltman.com>
* @Description //TODO 
* @File: mcp_server_run.py
* @Time: 2025/11/20
* @All Rights Reserve By Brtc
'''
from datetime import datetime, time

from mcp_core.mcp_protocol import Tool, ToolParameter
from mcp_core.mcp_server import MCPServer



def register_example_tools(server: MCPServer):
    def add_numbers(a:float, b:float) -> float:
        """两个数字相加"""
        return a+b
    add_tool = Tool(
        name = "add",
        description = "用于两个数字相加",
        parameters=[
            ToolParameter("a", "number", "第一个数字", required=True),
            ToolParameter("b", "number", "第二个数字", required=True)
        ],
        handler=add_numbers
    )
    server.register_tool(add_tool)


    def to_upercase(text: str) -> str:
        return text.upper()

    uper_casetool = Tool(
        name = "to_uppercase",
        description = "将字符串转成大写",
        parameters=[
            ToolParameter("text", "string", "要转换的字符串",required=True)
        ],
        handler=to_upercase
    )
    server.register_tool(uper_casetool)


    def get_timestamp(format_type: str="iso") -> str:
        if format_type == "iso":
            return datetime.utcnow().isoformat() + "Z"
        elif format_type == "unix":
            return str(int(datetime.now().timestamp()))
        else:
            return datetime.now().strftime(format_type)

    timestamp_tool = Tool(
        name="get_timestamp",
        description="获取时间戳",
        parameters=[
            ToolParameter("format_type", "string", "事件格式类型: iso, unix, 或自定义格式", required=False, default="iso")
        ],
        handler=get_timestamp
    )
    server.register_tool(timestamp_tool)


if __name__ == '__main__':
    server = MCPServer(host='0.0.0.0', port=8080)
    register_example_tools(server)
    try:
        server.start()
    except KeyboardInterrupt:
        print('Server stopped')
        server.stop()